<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插槽slot</title>
    <!--
    需求：需要把下面的内容，让标题和内容通过插槽插入内容
    <p>标题</p>
    <ul>
        <li>内容</li>
        <li>内容</li>
        <li>内容</li>
    </ul>
    -->
</head>
<body>
<!--
将数据通过插槽插入预留出来的位置
slot是绑定组件用的
:title是v-bind:title的缩写
-->
<div id="vue">
    <todo>
        <todo-title slot="todo-title" :title="title"></todo-title>
        <todo-items slot="todo-items" v-for="(item, index) in todoItems"
                    v-bind:item="item" v-bind:index="index"></todo-items>
    </todo>
</div>

<!--1.导入Vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script type="text/javascript">
    Vue.component("todo", {
        template: '<div>\
                    <slot name="todo-title"></slot>\
                        <ul>\
                            <slot name="todo-items"></slot>\
                        </ul>\
                   </div>'
    });
    Vue.component("todo-title", {
        props: ["title"],
        template: "<div>{{title}}</div>"
    });
    //这里的index，就是数组的下标，使用for循环遍历的时候，可以循环出来！
    Vue.component("todo-items", {
        props: ["item", "index"],
        template: "<li>{{index+1}}.{{item}}</li>"
    });
    //实例化Vue并初始化数据
    let vm = new Vue({
        el: "#vue",
        data: {
            title: "Games",
            todoItems: ["Dark Soul 3", "Destiny 2", "Far Cry 5"]
        }
    });
</script>
</body>
</html>